package com.video.user.controller;


import com.video.common.result.ResponseResult;
import com.video.common.utils.UserContext;
import com.video.user.domain.entity.LikeUser;
import com.video.user.service.ILikeUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 用户点赞表 前端控制器
 * </p>
 *
 * @author la
 * @since 2024-11-18
 */
@RestController
@RequestMapping("/like-user")
@RequiredArgsConstructor
public class LikeUserController {

    private final ILikeUserService service;


    /*
     * 查询用户是否点赞过该视频
     * */
    @GetMapping("/queryLike")
    public ResponseResult queryLike(Long videoId) {
        Long user = UserContext.getUser();
        // 查询数据是否存在
        Long count = service.lambdaQuery()
                .eq(videoId != null, LikeUser::getVideoId, videoId)
                .eq(user != null, LikeUser::getUserId, user)
                .count();

        Map<String, Object> map = new HashMap<>();
        // 判断是否存在
        if (count > 0) {
            map.put("isLike", true);
        } else {
            map.put("isLike", false);
        }
        return ResponseResult.okResult(map);
    }
}
